<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台登录页面</title>
    <link rel="stylesheet" href="__PUBLIC__/admin/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/admin/css/style.css">
    <link rel="icon" href="__PUBLIC__/admin/image/code.png">
</head>
<body class="login-body body">

<div class="login-box">
    <form class="layui-form layui-form-pane" method="post" action="{:url('index')}">
        <div class="layui-form-item">
            <h3>金钻石后台登录</h3>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号：</label>

            <div class="layui-input-inline">
                <input type="text" name="username" class="layui-input" lay-verify="account" placeholder="账号" autocomplete="on" maxlength="20"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码：</label>

            <div class="layui-input-inline">
                <input type="password" name="password" class="layui-input" lay-verify="password" placeholder="密码" maxlength="20"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">验证码：</label>

            <div class="layui-input-inline">
                <input type="text" name="code" style="width: 50%;float: left;" class="layui-input" lay-verify="code" placeholder="验证码" maxlength="4"/>
                <!--<img src="{:url('admin/login/verify')}" id="verify" onclick="this.src='{:url("admin/login/verify")}?'+ Math.random()" style="cursor: pointer;" alt="验证码">-->
                <img src="{:url('/img.php')}" id="verify" onclick="this.src='{:url("/img.php")}?'+ Math.random()" style="cursor: pointer;" alt="验证码">
            </div>
        </div>
        <div class="layui-form-item">
            <button type="reset" class="layui-btn layui-btn-danger btn-reset">重置</button>
            <button type="button" class="layui-btn btn-submit" lay-submit="" lay-filter="sub">立即登录</button>
        </div>
    </form>
</div>

<script type="text/javascript" src="__PUBLIC__/admin/frame/layui/layui.js"></script>

<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery,form = layui.form,layer = layui.layer;
        // 验证
        form.verify({
            account: function (value) {
                if (value == "") {
                    return "请输入用户名";
                }
            },
            password: function (value) {
                if (value == "") {
                    return "请输入密码";
                }
            },
            code: function (value) {
                if (value == "") {
                    return "请输入验证码";
                }
            }
        });
        $(document).keyup(function(event){
            if(event.keyCode ==13){
                $(".btn-submit").trigger("click");
            }
        });
        // 登录提交监听
        form.on('submit(sub)', function (data) {
            /*layer.alert(JSON.stringify(data.field), {
             title: '最终的提交信息'
             });*/
            // 提交到方法 默认为本身
            $.post($('.layui-form').attr('action'), data.field, function(res){
                if(res.code > 0){
                    layer.msg(res.msg,{time:1800},function(){
                        location.href = "{:url('index/index')}";
                    });
                }else{
                    layer.msg(res.msg,{time:1800});
                    $('#verify').click();
                }
            });
            return false;
        });
    })

</script>
</body>
</html>